<template>
  <div :style="styleItem">
    <!-- :style="{height: styleItem.height, width: styleItem.width}" -->
    <div id="InOutBoundCharts"></div>
  </div>
</template>

<script>
// 
// 0是出库   1是进库
import * as echarts from "echarts";
export default {
  name: "InOutBoundCharts",
  props: {
    styleItem: {
      type: Object,
      default: () => {},
    },
    Totalarchives: {
      type: Array,
      default: () => [],
    },
    xData: {
      type: Array,
      default: () => [],
    },
    inOutDepotData: {
      type: Array,
      default: () => [],
    }
  },
  data() {
    return {
      myChart: null,
      inDepotData:[],
      inDepotTime: [],
      outDepotData: [],
      outDepotTime: []

    };
  },
  mounted() {
    console.log('---------0---hhhh')
    // this.getMoreData()
    this.showChart();
  },
  methods: {
    getMoreData() {
      this.inDepotData = []
      this.inDepotTime = []
      this.outDepotData = []
      this.outDepotTime = []

      this.inOutDepotData.map(m => {
        if (m.action == 1) {
          this.inDepotData.push(m.total)
          this.inDepotTime.push(m.day)
        }
        if (m.action == 0) {
          this.outDepotData.push(m.total)
          this.outDepotTime.push(m.day)
        }
      })
    },
    reloadChart() {
      // console.log("重庆哦", this.styleItem);
      this.myChart.clear();
      this.getMoreData();
      this.showChart();
    },
    showChart() {
      if (
        this.myChart != null &&
        this.myChart != "" &&
        this.myChart != "undefined"
      ) {
        this.myChart.dispose();
      }
      var chartDom = document.getElementById("InOutBoundCharts");
      this.myChart = echarts.init(chartDom);
      var option;

      // console.log(this.Totalarchives, "Totalarchives");

      option = {
        // x轴
        xAxis: [
          {
            type: "category",
            data: this.inDepotTime,
            // ["Mon", "Tue", "Wed", "Thu", "Fri", ]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  "Sat", "Sun"],

            triggerEvent: true,
            axisTick: {
              show: false,
              inside: true,
              lineStyle: {
                color: "#ccc",
              },
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(69, 240, 234, 1)",
              },
            },
            axisLabel: {
              color: "#ccc",
              fontSize: this.$fontSize.fontSize(0.12),
              // fontWeight: 900
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            // data: this.Totalarchives,
            splitLine: {
              show: true,
              lineStyle: {
                type: "solid",
                width: 1,
                color: "#636363",
              },
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(69, 240, 234, 1)",
              },
            },
            axisLabel: {
              color: "#ccc",
              fontSize: this.$fontSize.fontSize(0.12),
            },
          },
        ],

        color: ["rgb(1, 217, 254)"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
            shadowStyle: {
              // 阴影指示器样式设置
              width: "auto", // 阴影大小
              color: "rgba(150,150,150,0.3)", // 阴影颜色
            },
          },
        },
        legend: {
          // icon: "rect",
          top: "0",
          right: "2%",
          // // bottom: 0,
          itemWidth: this.$fontSize.fontSize(0.1),
          itemHeight: this.$fontSize.fontSize(0.1),
          itemGap: this.$fontSize.fontSize(0.12),
          textStyle: {
            color: "#fff",
            fontSize: this.$fontSize.fontSize(0.1),
          },
          data: ["进库量", "出库量"],
        },
        grid: {
          top: "22%", // 组件离容器上侧的距离,百分比字符串或整型数字
          left: "5%", // 组件离容器左侧的距离,百分比字符串或整型数字
          right: "5%",
          bottom: "3%",
          containLabel: true, //grid 区域是否包含坐标轴的刻度标签，
        },
        // series: [
        //   {
        //     data: this.Totalarchives,
        // 		// [120, 200, 150, 80, 70, 110, 130],
        //     type: "bar",
        //   },
        // ],
        series: [
          {
            name: "进库量",
            type: "bar",
            barWidth: this.$fontSize.fontSize(0.2),
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#23e1e4",
                  },

                  {
                    offset: 1,
                    color: "#14c7cb",
                  },
                ]),
                label: {
                  show: true, //开启显示
                  position: "top", // 在上方显示
                  offset: [-4, 3], // 偏移量 调整文本位置
                  textStyle: {
                    //数值样式
                    color: "#fff",
                    fontSize: this.$fontSize.fontSize(0.1),
                  },
                },
              },
            },
            data: this.inDepotData,
            // [1300, 1200, 5000, 3000, 3650, 1450, 3260]
          },
          {
            name: "出库量",
            type: "bar",
            barWidth: this.$fontSize.fontSize(0.2),
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#83a8f4",
                  },

                  {
                    offset: 1,
                    color: "#6a96f3",
                  },
                ]),
                label: {
                  show: true, //开启显示
                  position: "top", //在上方显示
                  offset: [4, 3], //偏移量
                  textStyle: {
                    //数值样式
                    color: "#fff",
                    fontSize: this.$fontSize.fontSize(0.1),
                  },
                },
              },
            },
            data: this.outDepotData,
          //  / [1320, 200, 3270, 6000, 3650, 1450, 500]
          },
          
        ],
      };

      option && this.myChart.setOption(option);

      window.addEventListener("resize", function() {
        // console.log("动了");
        // this.myChart.resize();
      });
    },
  },
};
</script>

<style lang="scss">
#InOutBoundCharts {
  width: 100%;
	height: 100%;
}
</style>
